import Vue from 'vue'
import router from '../router'
import $A from '#/assets/js/public.js'

//页签左上方返回按钮
Vue.directive('close', {
  inserted(el, binding) {
    el.addEventListener('click', event => {
      !binding.value && router.back();
      binding.value && router.replace(binding.value);
    }, false)
  },
})
//跳转
Vue.directive('push', {
  inserted(el, binding) {
    el.addEventListener('click', event => {
      if (binding.value && binding.value.push) {
        router.push({ path: binding.value[0], query: binding.value[1] })
      } else {
        router.push(binding.value);
      }
    }, false)
  },
})
//权限
Vue.directive('power', {
  inserted(el, binding) {
    let value = binding.value
    if (!value) {
      return;
    }
    let allPower = $A.GS('P')
    let arr = allPower.filter(o => o == value)
    if (arr.length <= 0) {
      el.parentNode.removeChild(el);
      return;
    }
  },
})
